﻿SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ARITHABORT ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[bhp_TranslatorSetGroupState] (
	@GroupName			NVARCHAR(100),
	@SupportTranslate	BIT
)
AS
BEGIN

	DECLARE
		@GroupId	INT

	SELECT @GroupId = id FROM n_Tree WHERE name = @GroupName AND parent = 0
	IF EXISTS(SELECT * FROM bht_Groups WHERE Id = @GroupId)
		UPDATE
			bht_Groups
		SET
			EnableTranslate = @SupportTranslate
		WHERE
			Id = @GroupId
	ELSE
	BEGIN
		IF @SupportTranslate = 0
		BEGIN
			INSERT INTO bht_Groups (Id, Name, EnableTranslate, ReadOnly)
				SELECT id, name, @SupportTranslate, 0 FROM n_Tree WHERE id = @GroupId
		END
	END

	UPDATE
		n_Tree
	SET
		mtime = GETDATE(),
		muser = 3
	WHERE
		id = @GroupId
END